<?php
if (!defined('ROOT_PATH')) die('No direct access.');

function view_blog($param){
	view_header_top();
	//----------------------------------------------------------------
	$title = "Realita - Blog";
	$content = "Realita UMKM";
	$url = HOME_URL;
	$image = IMAGE_URL."300x240.gif";	//profpic orangnya / tokonya
	$desc = "Beranda sistem RealiTA UMKM";
	$auth = "RealiTA";
	$qwords = "utama, marketplace, umkm";
	//----------------------
	echo "<title>$title</title>";
	//<!--META DATA Open Graph-->
	echo "<meta property=\"og:title\" content=\"$title\"/>";
	echo "<meta property=\"og:type\" content=\"$content\"/>";
	echo "<meta property=\"og:url\" content=\"$url\"/>";
	echo "<meta property=\"og:image\" content=\"$image\"/>";
	echo "<meta property=\"og:site_name\" content=\"RealiTA UMKM\"/>";
	echo "<meta property=\"og:description\" content=\"$desc\" />";
	//<!--META DATA FB-->
	echo "<meta property=\"fb:app_id\" content=\"147346958657510\" />";
	//<!--META DATA-->
	echo "<meta name=\"author\" content=\"$auth\" />";
	echo "<meta name=\"keywords\" content=\"$qwords\" />";
	echo "<meta name=\"description\" content=\"$desc\" />";
	echo "<meta name=\"robots\" content=\"ALL\" />";
	echo "<meta charset=\"UTF-8\" />";
	//----------------------------------------------------------------
	view_header_bottom();
	$head = "";
	$crt = "";
	if (isset($param[1])){
		$crt = $param[1];
		switch ($param[1]){
			case "fashion" :
				$head = "Fashion<br />";
				break;
			case "elektronik" :
				$head = "Alat Elektronik<br />";
				break;
			case "kesehatan" :
				$head = "Kesehatan & Kecantikan<br />";
				break;
			case "perlengkapan" :
				$head = "Perlengkapan<br />";
				break;
			case "seni" :
				$head = "Kesenian & Kerajinan Tangan<br />";
				break;
			case "hobi" :
				$head = "Hobi & Olahraga<br />";
				break;
			case "kebun" :
				$head = "Kebun & Taman<br />";
				break;
			case "makanan" :
				$head = "Makanan<br />";
				break;
			case "lain" :
				$head = "Lain-lain<br />";
				break;
			default:
				$head = "";
				break;
		}
	}
?>
<!-- Content -->
<!-- Main Page Content and Sidebar -->
  <div class="row">
    <!-- Main Blog Content -->
    <a href="<?php echo BLOG_URL.$param[1] ?>"><h1>Blog <?php echo $head; ?><small>Cerita para pengguna</small></h1></a>
    <div class="large-9 columns" role="content">
      <article>
		<?php
			$query = getBlog($crt);
			$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
			if (strpos($url,'?')>0) $url = substr($url,0,strpos($url,'?'));
			$url.="?";
			$result = paginasi($query,$url,1);
			$articles = $result['sql'];
			if (count($articles)<1){
				echo "<h3>Belum ada artikel</h3>";
			}else{
				foreach ($articles as $article){
		?>
        <h3><a href="<?php echo BLOG_URL.'a/'.$article['idArtikel'].'/'.$article['slug-judul'] ?>"><?php echo $article['judul'] ?></a></h3>
        <h6>Ditulis oleh <a href="<?php echo PROFIL_URL.'a/'.$article['idFB'] ?>"><?php echo $article['nama']; ?></a> pada <?php echo convDate($article['tanggal']); ?>,
        untuk <?php echo "<a href=\"".BARANG_URL."a/".$article['idBarang']."/".$article['nama_barang']."\">".$article['nama_barang']."</a>" ?></h6>
        <div class="row">
          <div class="large-6 columns">
            <?php echo html_entity_decode($article['isi']); ?>
          </div>
        </div>
        <p><a href="<?php echo BLOG_URL.'a/'.$article['idArtikel'].'/'.$article['slug-judul'] ?>">Baca selengkapnya&rarr;</a></p>
      </article>
      <? }
	  echo $result['page'];
		}
	?>
    </div>
    <!-- End Main Content -->

    <!-- Sidebar -->
    <aside class="large-3 columns">
      <h5>Kategori</h5>
      <ul class="side-nav">
		<li><a href="<?php echo BLOG_URL.'' ?>">Semua</a></li>
        <li><a href="<?php echo BLOG_URL.'fashion' ?>">Fashion</a></li>
        <li><a href="<?php echo BLOG_URL.'elektronik' ?>">Alat Elektronik</a></li>
        <li><a href="<?php echo BLOG_URL.'kesehatan' ?>">Kesehatan &amp; Kecantikan</a></li>
        <li><a href="<?php echo BLOG_URL.'perlengkapan' ?>">Perlengkapan</a></li>
        <li><a href="<?php echo BLOG_URL.'seni' ?>">Kesenian &amp; Kerajinan Tangan</a></li>
        <li><a href="<?php echo BLOG_URL.'hobi' ?>">Hobi &amp; Olahraga</a></li>
        <li><a href="<?php echo BLOG_URL.'kebun' ?>">Kebun &amp; Taman</a></li>
        <li><a href="<?php echo BLOG_URL.'makanan' ?>">Makanan</a></li>
        <li><a href="<?php echo BLOG_URL.'lain' ?>">Lain-lain</a></li>
      </ul>
      <div class="panel">
        <h5>Terbaru</h5>
        <?php
			$articles = getNewArt();
			foreach ($articles as $article){
				echo "<p>";
					echo "<a href=\"".BLOG_URL.'a/'.$article['idArtikel'].'/'.$article['slug-judul']."\">".$article['judul']."</a>";
				echo "</p>";
			}
		  ?>
      </div>

    </aside>

    <!-- End Sidebar -->
  </div>

  <!-- End Main Content and Sidebar -->
<!-- End Content -->
<?php
	view_footer();
}

function view_artikel($id){
	view_header_top();
	//----------------------------------------------------------------
	$artikel = getArtikel($id);
	$title = "Realita - ".$artikel['judul'];
	$content = "Realita UMKM";
	$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
	$image = IMAGE_URL."300x240.gif";	//profpic orangnya / tokonya
	$desc = "Beranda sistem RealiTA UMKM";
	$auth = "RealiTA";
	$qwords = $artikel['tag'];
	//----------------------
	echo "<title>$title</title>";
	//<!--META DATA Open Graph-->
	echo "<meta property=\"og:title\" content=\"$title\"/>";
	echo "<meta property=\"og:type\" content=\"$content\"/>";
	echo "<meta property=\"og:url\" content=\"$url\"/>";
	echo "<meta property=\"og:image\" content=\"$image\"/>";
	echo "<meta property=\"og:site_name\" content=\"RealiTA UMKM\"/>";
	echo "<meta property=\"og:description\" content=\"$desc\" />";
	//<!--META DATA FB-->
	echo "<meta property=\"fb:app_id\" content=\"147346958657510\" />";
	//<!--META DATA-->
	echo "<meta name=\"author\" content=\"$auth\" />";
	echo "<meta name=\"keywords\" content=\"$qwords\" />";
	echo "<meta name=\"description\" content=\"$desc\" />";
	echo "<meta name=\"robots\" content=\"ALL\" />";
	echo "<meta charset=\"UTF-8\" />";
	//----------------------------------------------------------------
	view_header_bottom();
	$tipe = ($artikel['type']==1) ? 'toko' : 'barang';
?>
<!-- Content -->
<!-- Main Page Content and Sidebar -->
  <div class="row">
    <!-- Main Blog Content -->
    <a href="<?php echo BLOG_URL ?>"><h1>Blog <small>Cerita para pengguna</small></h1></a>
    <div class="large-9 columns" role="content">
      <article>
        <h3><?php echo $artikel['judul']; ?></h3>
        <h5><a href="<?php echo BLOG_URL.'edit/'.$artikel['idArtikel'].'/'.$artikel['idReview'].'/'.$tipe ?>">[edit]</a></h5>
        <h6>Ditulis oleh <a href="<?php echo PROFIL_URL.'a/'.$artikel['idFB'] ?>"><?php echo $artikel['nama']; ?></a> pada <?php echo convDate($artikel['tanggal']); ?>,
        untuk <?php echo "<a href=\"".BARANG_URL."a/".$artikel['idBarang']."/".$artikel['nama_barang']."\">".$artikel['nama_barang']."</a>" ?></h6>
        <div class="row">
          <div class="large-6 columns">
          <a href="#" onclick="
    window.open(
      'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href), 
      'facebook-share-dialog', 
      'width=626,height=436'); 
    return false;"><img src="<?php echo IMAGE_URL ?>fb-share-button.gif" /></a> 
		  <div class="fb-like" data-href="http://cafe.idebeda.com/ronda-sebagai-programmer/" data-width="The pixel width of the plugin" data-height="The pixel height of the plugin" data-colorscheme="light" data-layout="button_count" data-action="like" data-show-faces="true" data-send="false"></div>
        </div></div><br />
        <div class="row">
          <div class="large-6 columns">
            <?php echo html_entity_decode($artikel['isi']); ?>
          </div>
        </div>
      </article>
    </div>
    <!-- End Main Content -->

    <!-- Sidebar -->
    <aside class="large-3 columns">
      <h5>Kategori</h5>
      <ul class="side-nav">
        <li><a href="<?php echo BLOG_URL.'' ?>">Semua</a></li>
        <li><a href="<?php echo BLOG_URL.'?crt=0' ?>">Toko</a></li>
        <li><a href="<?php echo BLOG_URL.'?crt=1' ?>">Fashion</a></li>
        <li><a href="<?php echo BLOG_URL.'?crt=2' ?>">Alat Elektronik</a></li>
        <li><a href="<?php echo BLOG_URL.'?crt=3' ?>">Kesehatan &amp; Kecantikan</a></li>
        <li><a href="<?php echo BLOG_URL.'?crt=4' ?>">Perlengkapan</a></li>
        <li><a href="<?php echo BLOG_URL.'?crt=5' ?>">Kesenian &amp; Kerajinan Tangan</a></li>
        <li><a href="<?php echo BLOG_URL.'?crt=6' ?>">Hobi &amp; Olahraga</a></li>
        <li><a href="<?php echo BLOG_URL.'?crt=7' ?>">Kebun &amp; Taman</a></li>
        <li><a href="<?php echo BLOG_URL.'?crt=8' ?>">Makanan</a></li>
        <li><a href="<?php echo BLOG_URL.'?crt=9' ?>">Lain-lain</a></li>
      </ul>
      <div class="panel">
        <h5>Terkait</h5>
        <p>
			<a href="#">Ini Judul </a>
        </p>
        <p>
			<a href="#">Ini Judul </a>
        </p>
        <p>
			<a href="#">Ini Judul </a>
        </p>
      </div>
    </aside>

    <!-- End Sidebar -->
  </div>

  <!-- End Main Content and Sidebar -->
<!-- End Content -->
<?php
	view_footer();
}

function view_buat($id,$tipe){
	view_header_top();
	//----------------------------------------------------------------
	$title = "Realita - Buat Artikel";
	$content = "Realita UMKM";
	$url = HOME_URL;
	$image = IMAGE_URL."300x240.gif";	//profpic orangnya / tokonya
	$desc = "Beranda sistem RealiTA UMKM";
	$auth = "RealiTA";
	$qwords = "utama, marketplace, umkm";
	//----------------------
	echo "<title>$title</title>";
	//<!--META DATA Open Graph-->
	echo "<meta property=\"og:title\" content=\"$title\"/>";
	echo "<meta property=\"og:type\" content=\"$content\"/>";
	echo "<meta property=\"og:url\" content=\"$url\"/>";
	echo "<meta property=\"og:image\" content=\"$image\"/>";
	echo "<meta property=\"og:site_name\" content=\"RealiTA UMKM\"/>";
	echo "<meta property=\"og:description\" content=\"$desc\" />";
	//<!--META DATA FB-->
	echo "<meta property=\"fb:app_id\" content=\"147346958657510\" />";
	//<!--META DATA-->
	echo "<meta name=\"author\" content=\"$auth\" />";
	echo "<meta name=\"keywords\" content=\"$qwords\" />";
	echo "<meta name=\"description\" content=\"$desc\" />";
	echo "<meta name=\"robots\" content=\"ALL\" />";
	echo "<meta charset=\"UTF-8\" />";
	//----------------------------------------------------------------
	?>
	<script src="<?php echo ASSET_URL."nicedit/"; ?>nicEdit.js" type="text/javascript"></script>
	<script type="text/javascript">
	//editor text
	bkLib.onDomLoaded(function() {
		new nicEditor({iconsPath : '<?php echo ASSET_URL.'nicedit/'; ?>nicEditorIcons.gif'}).panelInstance('isi');
	});
	</script>
	<?php
	view_header_bottom();
?>
<!-- Content -->
<!-- Main Page Content and Sidebar -->
  <div class="row">
    <!-- Main Blog Content -->
    <h1>Buat Artikel</h1>
    <?php
	  if (isset($_SESSION['message'])) {
			echo "<div class='alert-box alert'>".$_SESSION['message']."<a href='#' class='close'>&times;</a></div>";
			unset($_SESSION['message']);
	}
	if ($tipe=='barang'){
		$judul = getBarang($id);
		$judul = $judul['nama'];
	}else{
		$judul = getUser($id);
		$judul = $judul['nama-toko'];
	}
	?>
    <h3>Artikel : <?php echo $judul; ?></h3>
    <div class="large-9 columns" role="content">
      <div class="row" style="display:block" id="isian">
		<form method="post" action="">
		<input type="hidden" name="idrev" value="<?php echo $id;?>" />
		<div class="large-12 columns">
			<div class="row">
				<div class="large-12 columns">
					<label>Judul Artikel</label>
					<input type="text" name="judul" placeholder="Judul artikel...">
				  </div>
			</div>
			<div class="row">
				<div class="large-12 columns">
					<label>Isi Artikel</label>
					<textarea name="isi" id="isi"></textarea>
				 </div>
			</div>
			<br />
			<div class="row">
				<div class="large-12 columns">
					<label>Tag Artikel</label>
					<input type="text" name="tag" placeholder="Pisahkan dengan koma">
				</div>
			</div>
			<div class="row">
				<div class="large-12 columns">
					<input class="button" name="submit" type="submit" value="Buat Artikel"/>
				  </div>
			</div>
		</div>
		</form>
	</div>
    </div>
    <!-- End Main Content -->
  </div>
  <!-- End Main Content and Sidebar -->
<!-- End Content -->
<?php
	view_footer();
}

function edit_buat($idart,$id,$tipe){
	view_header_top();
	//----------------------------------------------------------------
	$title = "Realita - Buat Artikel";
	$content = "Realita UMKM";
	$url = HOME_URL;
	$image = IMAGE_URL."300x240.gif";	//profpic orangnya / tokonya
	$desc = "Beranda sistem RealiTA UMKM";
	$auth = "RealiTA";
	$qwords = "utama, marketplace, umkm";
	//----------------------
	echo "<title>$title</title>";
	//<!--META DATA Open Graph-->
	echo "<meta property=\"og:title\" content=\"$title\"/>";
	echo "<meta property=\"og:type\" content=\"$content\"/>";
	echo "<meta property=\"og:url\" content=\"$url\"/>";
	echo "<meta property=\"og:image\" content=\"$image\"/>";
	echo "<meta property=\"og:site_name\" content=\"RealiTA UMKM\"/>";
	echo "<meta property=\"og:description\" content=\"$desc\" />";
	//<!--META DATA FB-->
	echo "<meta property=\"fb:app_id\" content=\"147346958657510\" />";
	//<!--META DATA-->
	echo "<meta name=\"author\" content=\"$auth\" />";
	echo "<meta name=\"keywords\" content=\"$qwords\" />";
	echo "<meta name=\"description\" content=\"$desc\" />";
	echo "<meta name=\"robots\" content=\"ALL\" />";
	echo "<meta charset=\"UTF-8\" />";
	//----------------------------------------------------------------
	$artikel = getArtikel($idart);
	?>
	<script src="<?php echo ASSET_URL."nicedit/"; ?>nicEdit.js" type="text/javascript"></script>
	<script type="text/javascript">
	//editor text
	bkLib.onDomLoaded(function() {
		new nicEditor({iconsPath : '<?php echo ASSET_URL.'nicedit/'; ?>nicEditorIcons.gif'}).panelInstance('isi');
	});
	</script>
	<?php
	view_header_bottom();
?>
<!-- Content -->
<!-- Main Page Content and Sidebar -->
  <div class="row">
    <!-- Main Blog Content -->
    <h1>Edit Artikel</h1>
    <?php
	  if (isset($_SESSION['message'])) {
			echo "<div class='alert-box alert'>".$_SESSION['message']."<a href='#' class='close'>&times;</a></div>";
			unset($_SESSION['message']);
	}
	if ($tipe=='barang'){
		$judul = getBarang($id);
		$judul = $judul['nama'];
	}else{
		$judul = getUser($id);
		$judul = $judul['nama-toko'];
	}
	?>
    <h3>Artikel : <?php echo $judul; ?></h3>
    <div class="large-9 columns" role="content">
      <div class="row" style="display:block" id="isian">
		<form method="post" action="">
		<input type="hidden" name="index" value="<?php echo $artikel['idArtikel'];?>" />
		<div class="large-12 columns">
			<div class="row">
				<div class="large-12 columns">
					<label>Judul Artikel</label>
					<input type="text" name="judul" value="<?php echo $artikel['judul'];?>">
				  </div>
			</div>
			<div class="row">
				<div class="large-12 columns">
					<label>Isi Artikel</label>
					<textarea name="isi" id="isi"><?php echo html_entity_decode($artikel['isi']);?></textarea>
				 </div>
			</div>
			<br />
			<div class="row">
				<div class="large-12 columns">
					<label>Tag Artikel</label>
					<input type="text" name="tag" value="<?php echo $artikel['tag'];?>">
				</div>
			</div>
			<div class="row">
				<div class="large-12 columns">
					<input class="button" name="submit" type="submit" value="Edit Artikel"/>
				  </div>
			</div>
		</div>
		</form>
	</div>
    </div>
    <!-- End Main Content -->
  </div>
  <!-- End Main Content and Sidebar -->
<!-- End Content -->
<?php
	view_footer();
}
